import java.util.Scanner;

/**
 * Created by forcht on 2018/4/22.
 */
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        char[] chars = {'Z', 'O', 'W', 'T', 'U', 'F', 'X', 'S', 'G', 'I'};
        int[] num = new int[10];
        int t = scanner.nextInt();
        for (int i = 0; i < t; i++) {
            for(int j=0;j<10;j++){
                num[j]=0;
            }
            String s = scanner.next();
            for (int j = 0; j < s.length(); j++) {
                for (int k = 0; k < 10; k++) {
                    if(chars[k]==s.charAt(j)){
                        num[k]++;
                        break;
                    }
                }
            }
            //计算ONE
            num[1]=num[1]-num[0]-num[2]-num[4];
            //计算THREE
            num[3]=num[3]-num[2]-num[8];
            //计算FIVE
            num[5]=num[5]-num[4];
            //计算SEVEN
            num[7]=num[7]-num[6];
            //计算NINE
            num[9]=num[9]-num[5]-num[6]-num[8];
            for (int j=0;j<num[8];j++){
                System.out.print(0);
            }
            for (int j=0;j<num[9];j++){
                System.out.print(1);
            }
            int n=2;
            for (int j=0;j<8;j++){
                for (int k=0;k<num[j];k++){
                    System.out.print(n);
                }
                n++;
            }
            System.out.println();
        }
    }
}
